<script setup lang="ts">
import { ref } from 'vue'
import Service from '../../mock/Service'

const props = defineProps<{ data: ProjectRaw[] }>()

const projects = ref(props.data.map(projectRaw=>{return {...projectRaw,name:"",description:""}}) as Project[]);

props.data.forEach((project) => {
    Service.getProject(project.id).then(_project => {
        if (_project == undefined)
            return;
        const target:Project | undefined = projects.value.find(project => project.id == _project.id)

        if(target == undefined) return

        target.name = _project.name
        target.description = _project.description
    })
});
</script>

<template>
    <div>
        
        <div class="project" v-for="project in projects">
            <div class="header">
                <h3>{{ project.name }}</h3>
                <div
                    class="right"
                >{{ project.session[0] }} - {{ project.session[1] ? project.session[1] : "至今" }}</div>
            </div>
            <div class="description">{{ project.description }}</div>
        </div>
    </div>
</template>

<style scoped>
.project {
    margin-bottom: 24px;
}

.project .header {
    display: flex;
    align-items: center;
}

.project h3 {
    flex: 1;
    color: black;
}

.project .right {
    width: 130px;
    text-align: right;
    font-size: 12px;
}

.project .description {
    font-size: 11px;
    line-height: 1.8;
}
</style>